function signum(x) {
    return x ? x < 0 ? -1 : 1 : 0;
}

function pointToLineSegmentDistance(a, b, c) {
    var l2 = b.sub(a).normSquared();
    if (l2 === 0.0) {
        return c.sub(a).norm();
    }
    var t = c.sub(a).dotProduct(b.sub(a)) / l2;
    if (t < 0.0) {
        return c.sub(a).norm();
    } else if (t > 1.0) {
        return c.sub(b).norm();
    }
    var projection = a.add(b.sub(a).mulS(t));
    var d = c.sub(projection);
    var e = d.norm2();
    return e;
}